﻿using System;

namespace Td.Additional
{
    /// <summary>
    /// String with optional object.
    /// </summary>
    public class TaggedString
    {
        #region Properties

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        /// <value>The text.</value>
        public String Text { get; set; }

        /// <summary>
        /// Gets or sets the tag.
        /// </summary>
        /// <value>The tag.</value>
        public Object Tag { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="TaggedString"/> class.
        /// </summary>
        public TaggedString()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TaggedString"/> class.
        /// </summary>
        /// <param name="text">The text.</param>
        public TaggedString(String text)
            : this()
        {
            Text = text;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TaggedString"/> class.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="tag">The tag.</param>
        public TaggedString(String text, Object tag)
            : this(text)
        {
            Tag = tag;
        }

        #endregion

        #region Overriden object methods

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            if (!String.IsNullOrEmpty(Text))
                return Text;
            if (Tag != null)
                return Tag.ToString();
            return base.ToString();
        }

        #endregion
    }
}